package com.myxy.mysqlilt;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getCanonicalName();

    private MyHelper mDBHelper;
    private TextView texts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
        view();
        textview();
    }
    private void view(){
        texts = findViewById(R.id.text);

        texts.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    private void textview(){
        sText("你好啊");
    }
    private void sText(String t) {
        texts.setText(t);
    }
    private void initData(){
        //数据库版本号默认从1开始
        mDBHelper = new MyHelper(this,"stuInfo.db",null,1);

        //mDBHelper.insertStu("张三","男","安卓","2022-2-12");
        //mDBHelper.insertStu("小李","女","java","2022-0202");
        //mDBHelper.updateStu("小张",1);
        //mDBHelper.deleteStu(3);

        //增加
        ContentValues values = new ContentValues();
        values.put(MyHelper.STU_NAME,"李四");
        values.put(MyHelper.STU_GENDER,"女");
        values.put(MyHelper.STU_MAJOR,"安卓");
        values.put(MyHelper.STU_GRADUATED,"2022-02-14");
        mDBHelper.insertStu2(values);

        //删除
        //mDBHelper.deleteStuByID("2");

        //修改
        mDBHelper.update("王五","3");

        //查询
        mDBHelper.queryAll("2022-02-14");
        for (int i = 0; i <mDBHelper.result.size(); i++){//测试
            Log.d(TAG,mDBHelper.result.get(i).toString());
        }

    }
}